<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*   //1. 求所有数组元素的和及平均值
        var a1 = [11, 22, 33, 44, 55, 66, 77, 99, 123, 432];
        var b = 0;
        // 1.1 定义一个和的变量  b;
        // 1.2去除数组中所有的元素依次和b累加
        for (var i = 0; i < a1.length; i++) {
          b = b + a1[i];
        }
        console.log(b); */

      //   2. 求数组中的最大值
      /*    var b1 = [11, 22, 33, 44, 55, 66, 885, 253453, 23423543534534];

        var z = b1[0];
        for (var i = 0; i < b1.length; i++) {
          if (b1[i] > z ){
            z = b1[i];
          }
        }
        console.log(b1[i]); */
      /*       // 3. 将数组转为字符串并以指定符号分隔
      var a1 = ['长沙', '武汉', '郑州', '南京'];
      var b = '';
      for (var i = 0; i < a1.length; i++) {
        b = b + a1[i] + '-';
      }
      console.log(b); */

      // 4. 翻转遍历
      var f1 = ['长沙', '武汉', '郑州', '南京'];
      var a1 = [];
      for (var i = f1.length - 1; i >= 0; i--) {
        a1[a1.length] = f1[i];
      }
      console.log(a1);
      //   console.log(a1.join('-'));  翻转简单粗暴
      //   console.log(a1.reverse))    翻转简单粗暴
    </script>
  </body>
</html>
